package com.franzliszt.OrderOnline.SQLite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Helper extends SQLiteOpenHelper {
    /**数据库名称*/
    public static final String DataBase = "OrderOnline.db";
    public static final SQLiteDatabase.CursorFactory factory = null;
    public static int version = 5;
    /**表名1*/
    public static final String TableName = "GoodsList";
    /**行名*/
    public static final String Row_ID = "ID";
    public static final String Row_User = "UserName";
    public static final String Row_PassWord = "PassWord";
    public static final String Row_GoodsImg = "GoodsImg";
    public static final String Row_GoodsName = "GoodsName";
    public static final String Row_GoodsPrice = "GoodsPrice";
    public static final String Row_GoodsNumber = "GoodsNumber";
    public static final String Row_GoodsSub = "GoodsSub";
    public static final String Row_GoodsAdd= "GoodsAdd";



    public Helper(@Nullable Context context) {
        super( context, DataBase, factory, version );
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table " + TableName + "("+Row_ID+" INTEGER primary key AUTOINCREMENT,"+Row_User+" varchar(20),"+Row_PassWord+" varchar(20),"+Row_GoodsImg+" INTEGER, "+Row_GoodsName+" varchar(20),"+Row_GoodsPrice+" REAL,"+Row_GoodsNumber+" INTEGER,"+Row_GoodsSub+" NUMERIC,"+Row_GoodsAdd+" NUMERIC);";
        //String sql_Information = "create table " + InformationTable + "("+Row_InformationAddress+" varchar(20) primary key, "+Row_InformationParkType+" varchar(20),"+Row_InformationShareMode+" varchar(20),"+Row_InformationLastName+" varchar(20),"+Row_InformationSex+" varchar(20),"+Row_InformationPhone+" varchar(20));";
        db.execSQL( sql );
        //db.execSQL( sql_Information );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
       // switch (oldVersion){
//            case 4:
//                String sql = "create table " + TableName + "("+Row_ID+" INTEGER primary key AUTOINCREMENT,"+Row_GoodsImg+" INTEGER, "+Row_GoodsName+" varchar(20),"+Row_GoodsPrice+" REAL,"+Row_GoodsNumber+" INTEGER,"+Row_GoodsSub+" NUMERIC,"+Row_GoodsAdd+" NUMERIC);";
//                db.execSQL( sql );
//            case 5:
//                String sql5 = "create table " + TableName + "("+Row_ID+" INTEGER primary key AUTOINCREMENT,"+Row_GoodsImg+" INTEGER, "+Row_GoodsName+" varchar(20),"+Row_GoodsPrice+" REAL,"+Row_GoodsNumber+" INTEGER,"+Row_GoodsSub+" NUMERIC,"+Row_GoodsAdd+" NUMERIC);";
//                db.execSQL( sql5 );
       // }
        db.execSQL("drop table if exists "+TableName);
        //db.execSQL("drop table if exists "+InformationTable);
        onCreate(db);
    }
}
